package main

import (
	"fmt"
	"strconv"
	"time"
)

func main() {

	ch1 := make(chan string, 0)
	fmt.Println(len(ch1), cap(ch1))

	ch2 := make(chan string, 3)
	fmt.Println(len(ch2), cap(ch2))

	go test(ch2)

	for v := range ch2 {
		time.Sleep(time.Second)
		fmt.Println("读到的数据", v)
	}

}

func test(ch chan string) {
	for i := 0; i < 10; i++ {
		ch <- "test-" + strconv.Itoa(i)
		fmt.Println("写入的数据时", "test-"+strconv.Itoa(i))
	}
	close(ch) //写入结束关闭通道
}
